#include <stdio.h>
#include <string.h>

#define STDIN
//#define DEBUG

int main()
{
#if defined(STDIN)
    freopen("bin/1565.in", "r", stdin);
#endif
    int i, xk, c = 1;
    char skew[100];
    int result = 0;

    while(1)
    {
        scanf("%s", skew);
        if ((skew[0] == '0') && strlen(skew) == 1)
            break;
#ifdef DEBUG
        printf("skew: %s\n", skew);
#endif
        c = 1;
        result = 0;

        for (i = strlen(skew)-1; i >= 0; i--)
        {
            xk = skew[i] - '0';
            result += xk * c;
            c = c * 2 + 1;
#ifdef DEBUG
            printf("xk: %d c: %d result: %d\n", xk, c, result);
#endif
        }

        printf("%d\n", result);
    }

    return 0;
}
